package com.zc.manager.device.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.manager.device.domain.IotDeviceTags;
import com.zc.manager.device.service.IIotDeviceTagsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 设备标签管理管理Controller
 *
 * @author xiepufeng
 * @date 2022-08-30
 */
@RestController
@RequestMapping("/iot/device/tags")
public class IotDeviceTagsController extends BaseController {
    @Resource
    private IIotDeviceTagsService iotDeviceTagsService;

    /**
     * 查询设备标签列表
     */
    @PreAuthorize("@ss.hasPermi('iot:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotDeviceTags iotDeviceTags) {
        startPage();
        List<IotDeviceTags> list = iotDeviceTagsService.selectIotDeviceTagsList(iotDeviceTags);
        return getDataTable(list);
    }

    /**
     * 无分页查询设备标签列表
     */
    @PreAuthorize("@ss.hasPermi('iot:device:list')")
    @GetMapping("/query")
    public AjaxResult query(IotDeviceTags iotDeviceTags) {
        List<IotDeviceTags> list = iotDeviceTagsService.selectIotDeviceTagsList(iotDeviceTags);
        return AjaxResult.success(list);
    }

    /**
     * 导出设备标签列表
     */
    @PreAuthorize("@ss.hasPermi('iot:device:export')")
    @Log(title = "导出设备标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotDeviceTags iotDeviceTags) {
        List<IotDeviceTags> list = iotDeviceTagsService.selectIotDeviceTagsList(iotDeviceTags);
        ExcelUtil<IotDeviceTags> util = new ExcelUtil<>(IotDeviceTags.class);
        util.exportExcel(response, list, "设备标签数据");
    }

    /**
     * 获取设备标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iotDeviceTagsService.selectIotDeviceTagsById(id));
    }

    /**
     * 新增设备标签
     */
    @PreAuthorize("@ss.hasPermi('iot:device:add')")
    @Log(title = "设备标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IotDeviceTags iotDeviceTags) {
        return toAjax(iotDeviceTagsService.insertIotDeviceTags(iotDeviceTags));
    }

    /**
     * 批量新增设备标签
     */
    @PreAuthorize("@ss.hasPermi('iot:device:add')")
    @Log(title = "设备标签管理", businessType = BusinessType.INSERT)
    @PostMapping("addBatch")
    public AjaxResult addBatch(@Valid @RequestBody List<IotDeviceTags> iotDeviceTagsList) {
        return toAjax(iotDeviceTagsService.insertListIotDeviceTags(iotDeviceTagsList));
    }

    /**
     * 修改设备标签
     */
    @PreAuthorize("@ss.hasPermi('iot:device:edit')")
    @Log(title = "设备标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IotDeviceTags iotDeviceTags) {
        return toAjax(iotDeviceTagsService.updateIotDeviceTags(iotDeviceTags));
    }

    /**
     * 批量删除设备标签
     */
    @PreAuthorize("@ss.hasPermi('iot:device:remove')")
    @Log(title = "设备标签管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult removeAll(@PathVariable Long[] ids) {
        return toAjax(iotDeviceTagsService.deleteIotDeviceTagsByIds(ids));
    }


}
